package dto.app;

import models.application.AniApp;
import services.exception.AniDataException;

import java.util.ArrayList;
import java.util.List;

/**
 * User: yeh
 * Date: 3/28/13
 * Time: 4:09 AM
 * For:  wilddragon
 */
public class AppInstallDto {
    Long appId;

    public AppInstallDto(Long appId) {
        this.appId = appId;
    }

    public static List<AppInstallDto> generateAppIdListFromStr(String idStr){
        List<AppInstallDto> appIds = new ArrayList<AppInstallDto>();
        try{
            for(String oneId: idStr.split(",")){
                appIds.add(
                        new AppInstallDto(
                                Long.valueOf(oneId)
                        )
                );
            }
        } catch (Exception e){
            throw new AniDataException("ID_ARRAY_FORMAT_ILLEGAL");
        }
        return appIds;
    }
    public static List<Long> getIdList(List<AppInstallDto> installApps){
        List<Long> appIdList = new ArrayList<Long>();
        if (installApps == null || installApps.isEmpty()){
            throw new AniDataException("INSTALL_APP_LIST_IS_EMPTY");
        }
        for(AppInstallDto oneInstallApp: installApps){
            appIdList.add(oneInstallApp.appId);
        }
        return appIdList;
    }
    public static List<AniApp> getAppsDao(List<AppInstallDto> apps){
        List<AniApp> appsDao = new ArrayList<AniApp>();
        for(AppInstallDto oneAppDto: apps){
            appsDao.add(new AniApp(oneAppDto.appId));
        }
        return appsDao;
    }
}
